#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "../../src/cdslib.h"

#define cast(x) (void *)(x)

int main() 
{
    Tree t;
    size_t i;
    Array a;
    initTree(&t, NULL);

    /* Testing length */
    assert(t.length == 0);

    /* Testing defined functions */
    TreeAdd(&t, cast(12));
    TreeAdd(&t, cast(13));
    TreeAdd(&t, cast(16));
    TreeAdd(&t, cast(8));
    TreeAdd(&t, cast(9));

    assert(TreeContains(&t, cast(12)) == 1);
    assert(TreeContains(&t, cast(13)) == 1);
    assert(TreeAdd(&t, cast(12)) == 0);
    assert(TreeAdd(&t, cast(11)) == 1);
    
    assert(TreeExtract(&t, cast(16)) == cast(16));
    assert(TreeExtract(&t, cast(1)) == NULL);

    a = deleteTree(&t);
    for(i = 0; i < a.length; i++) {
        printf("%d ", (int)ArrayGet(&a, i));
    }
    printf("\n");

    deleteArray(&a);

    return EXIT_SUCCESS;
}
